# CMakeList.txt: thirdx 的 CMake 项目，在此处包括源代码并定义
# 项目特定的逻辑。
#
cmake_minimum_required (VERSION 3.8) # 必须是3.8，否则即便编译选项加了/MTd，生成的vc工程也是/MDd!!!

project (x2lib)

include (options.cmake)

# 暂时切换debug和release需要手动删除build目录

IF(MSVC)
    add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/source-charset:utf-8>")
    add_compile_options("$<$<C_COMPILER_ID:MSVC>:/source-charset:utf-8>")
ENDIF()

add_custom_target(mergelibs ALL DEPENDS httplib sqlite3xx movcrypto pugixml wolfssl x2lib)

# set(WIN32 True)
# set(UNIX False)
# include_directories(/usr/i686-w64-mingw32/include/)

IF(WIN32)
	add_custom_command(TARGET mergelibs POST_BUILD 
		COMMAND lib /OUT:${DIR_OUTPUT}/${TAG_NAME}.lib
			pugixml/${CMAKE_BUILD_TYPE}/pugixml.lib
			httplib/${CMAKE_BUILD_TYPE}/httplib.lib
			sqlite3xx/${CMAKE_BUILD_TYPE}/sqlite3xx.lib
			movcrypto/${CMAKE_BUILD_TYPE}/movcrypto.lib
			x2lib/${CMAKE_BUILD_TYPE}/x2lib.lib)
ELSEIF(LINUX)
	add_custom_command(TARGET mergelibs POST_BUILD 
		COMMAND rm -rf merge_objs && mkdir merge_objs 
		COMMAND ar -x pugixml/libpugixml.a
		COMMAND ar -x httplib/libhttplib.a
		COMMAND ar -x movcrypto/libmovcrypto.a
		COMMAND ar -x sqlite3xx/libsqlite3xx.a
		COMMAND ar -x wolfssl/libwolfssl.a
		COMMAND ar -x x2lib/libx2lib.a
		COMMAND ar crv ${DIR_OUTPUT}/lib${TAG_NAME}.a ./*.o
		COMMAND rm -rf *.o)
ELSEIF(MACOS)
	add_custom_command(TARGET mergelibs POST_BUILD 
		COMMAND rm -rf merge_objs && mkdir merge_objs 
		COMMAND ar -x pugixml/libpugixml.a
		COMMAND ar -x httplib/libhttplib.a
		COMMAND ar -x movcrypto/libmovcrypto.a
		COMMAND ar -x sqlite3xx/libsqlite3xx.a
		COMMAND ar -x wolfssl/libwolfssl.a
		COMMAND ar -x x2lib/libx2lib.a
		COMMAND ar crv ${DIR_OUTPUT}/lib${TAG_NAME}.a ./*.o
		COMMAND rm -rf *.o)
ENDIF()


add_subdirectory(httplib)
add_subdirectory(wolfssl)
add_subdirectory(sqlite3xx)
add_subdirectory(movcrypto)
add_subdirectory(pugixml)
add_subdirectory(x2lib)

# add_library(merged_lib OBJECT)

# add_library(lib1 STATIC IMPORTED)
# set_target_properties(lib1 PROPERTIES IMPORTED_LOCATION httplib/libhttplib.a)
# add_library(lib2 STATIC IMPORTED)
# set_target_properties(lib2 PROPERTIES IMPORTED_LOCATION pugixml/libpugixml.a)
# add_library(lib3 STATIC IMPORTED)
# set_target_properties(lib3 PROPERTIES IMPORTED_LOCATION movcrypto/libmovcrypto.a)
# add_library(lib4 STATIC IMPORTED)
# set_target_properties(lib4 PROPERTIES IMPORTED_LOCATION sqlite3xx/libsqlite3xx.a)
# add_library(lib5 STATIC IMPORTED)
# set_target_properties(lib5 PROPERTIES IMPORTED_LOCATION wolfssl/libwolfssl.a)
# add_library(lib6 STATIC IMPORTED)
# set_target_properties(lib6 PROPERTIES IMPORTED_LOCATION x2lib/libx2lib.a)

# add_custom_target(mergelibs DEPENDS httplib sqlite3xx movcrypto pugixml wolfssl x2lib)
# add_dependencies(mergelibs lib1 lib2 lib3 lib4 lib5 lib6)


# # 将所有静态库的对象文件链接到 merged_lib 中
# target_sources(merged_lib PRIVATE
#     $<TARGET_OBJECTS:lib1>
#     $<TARGET_OBJECTS:lib2>
#     $<TARGET_OBJECTS:lib3>
#     $<TARGET_OBJECTS:lib4>
#     $<TARGET_OBJECTS:lib5>
#     $<TARGET_OBJECTS:lib6>
# )


# # 添加你的可执行文件
# add_executable(YourTarget main.cpp)

# # 链接合并库到你的目标
# target_link_libraries(YourTarget PRIVATE merged_lib)


# add_library(merged_lib OBJECT)
# target_sources(merged_lib PRIVATE httplib/libhttplib.a)
# target_sources(merged_lib PRIVATE pugixml/libpugixml.a)
# target_sources(merged_lib PRIVATE movcrypto/libmovcrypto.a)
# target_sources(merged_lib PRIVATE sqlite3xx/libsqlite3xx.a)
# target_sources(merged_lib PRIVATE wolfssl/libwolfssl.a)
# target_sources(merged_lib PRIVATE x2lib/libx2lib.a)

